#include "gui/VisualComponents/VisualComponentCompositeAttribute.h"
#include "gui/SubWindow/DrawingAreaPlusPlus.h"

VisualComponentCompositeAttribute::VisualComponentCompositeAttribute( Diagram& diagram) : VisualCompositeComponent(diagram) {
	m_component = new CompositeAttribute();
	initialize();
}

VisualComponentCompositeAttribute::VisualComponentCompositeAttribute(const VisualComponentCompositeAttribute& other) : VisualCompositeComponent(other.m_diagram) {
	m_component = new CompositeAttribute(*(CompositeAttribute*)other.m_component);
	initialize();
}

VisualCompositeComponent* VisualComponentCompositeAttribute::getCopy(){
	return new VisualComponentCompositeAttribute(*this);
}


InfluenceArea VisualComponentCompositeAttribute::getInfluenceArea() {
	return InfluenceRectangle(getX(), getY(), getX() + COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF + 3, getY() + COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_YF + 3);
}

void VisualComponentCompositeAttribute::draw(Cairo::RefPtr<Cairo::Context> ptrContext){
	ptrContext->save();

	int x = getX();
	int y = getY();

	ptrContext->translate(x + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF) / 2, y + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_YF) / 2);
	ptrContext->rotate_degrees(m_component->getType());
	ptrContext->translate(-(x + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF) / 2), -(y + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_YF) / 2));

	if (m_selected)
		ptrContext->set_source_rgb(0, 1, 0);
	else
		ptrContext->set_source_rgb(0, 0, 0);
	ptrContext->set_line_width(ANCHO_DE_LINEA);
	ptrContext->arc(x + CONECTOR_RADIUS + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF) / 2, y + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_YF) / 2 + CONECTOR_RADIUS,  (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF) / 2, -M_PI, M_PI);
	ptrContext->stroke_preserve();
	ptrContext->set_source_rgb(COLOR_COMPONENT);
	ptrContext->fill();

	ptrContext->restore();
	VisualCompositeComponent::draw( ptrContext);
	Draw draw;
	draw.writeTextInContext(ptrContext, x + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_XF) / 2, y + (COMPOSITEATTRIBUTE_INFLUENCE_RECTANGLE_YF) / 1.5, m_component->getName(), COLOR_IN_TEXT);
}
